package logic

import (
	"context"
	"video-management-system/userrpc/userrpc"

	"video-management-system/api/internal/svc"
	"video-management-system/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewVideoAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoAddLogic {
	return &VideoAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *VideoAddLogic) VideoAdd(req *types.VideoAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.UserRpc.VideoAdd(l.ctx, &userrpc.VideoAddRequest{
		Uid:           req.Uid,
		VideoTitle:    req.Videotitle,
		VideoCategory: req.Videocategory,
		VideoLink:     req.Videolink,
		CoverLink:     req.Coverlink,
		VideoIntro:    req.Videointro,
		Tid:           req.Tid,
		VideoStatus:   req.Videostatus,
	})

	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "视频发布成功",
		Data:    add,
		Code:    200,
	}, nil
}
